import 'package:flutter/material.dart';
import 'package:flutter_buisiness_2006a/provider/detail_info_provider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

class DetailTabBar extends StatelessWidget {
  const DetailTabBar({Key? key}) : super(key: key);

  Widget _myTabBarLeft(context, isLeft) {
    return InkWell(
      onTap: () {
        Provider.of<DetailInfoProvider>(context, listen: false)
            .changeLeftAndRight('left');
      },
      child: Container(
        padding: const EdgeInsets.all(10),
        alignment: Alignment.center,
        width: ScreenUtil().setWidth(375).toDouble(),
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border(
                bottom: BorderSide(
                    width: 5, color: isLeft ? Colors.pink : Colors.black12))),
        child: Text(
          '详情',
          style: TextStyle(color: isLeft ? Colors.pink : Colors.black),
        ),
      ),
    );
  }

  Widget _myTabBarRight(context, isRight) {
    return InkWell(
      onTap: () {
        Provider.of<DetailInfoProvider>(context, listen: false)
            .changeLeftAndRight('right');
      },
      child: Container(
        padding: const EdgeInsets.all(10),
        alignment: Alignment.center,
        width: ScreenUtil().setWidth(375).toDouble(),
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border(
                bottom: BorderSide(
                    width: 5, color: isRight ? Colors.pink : Colors.black12))),
        child: Text(
          '评论',
          style: TextStyle(color: isRight ? Colors.pink : Colors.black),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 15),
      child: Row(
        children: [
          _myTabBarLeft(
              context, Provider.of<DetailInfoProvider>(context).isLeft),
          _myTabBarRight(
              context, Provider.of<DetailInfoProvider>(context).isRight)
        ],
      ),
    );
  }
}
